package com.cinsea.ext.vmeeting;

import com.cinsea.common.Env;
import com.cinsea.common.ExtAction;
import com.cinsea.htmlselect.service.OptionService;
import com.cinsea.util.StringUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

/**
 * Created with IntelliJ IDEA.
 * User: xuhuanchao
 * Date: 13-5-9
 * Time: 下午12:56
 * To change this template use File | Settings | File Templates.
 */
public class VmeetingAction extends ExtAction {

    @Override
    public void execute(HttpServletRequest httpServletRequest,
                        HttpServletResponse httpServletResponse) throws IOException, ServletException {
        String action= StringUtil.null2String(httpServletRequest.getParameter("action"));
        if (action.equals("sendnotify")) {
            OptionService optionService = Env.getBean("optionService");
            String meetingURL = optionService.get("4028818e3e687c67013e688b8c480008").getObjdesc();
            String trainingPassword = httpServletRequest.getParameter("trainingPassword") == null ? "" : httpServletRequest.getParameter("trainingPassword");
            String confId = httpServletRequest.getParameter("confId") == null ? "" : httpServletRequest.getParameter("confId");
            String joinTime = httpServletRequest.getParameter("joinTime") == null ? "" : httpServletRequest.getParameter("joinTime");
            String registerUserName = Env.getRemoteUser().getUsername();//得到系统当前用户账号

            String URL = meetingURL+"/meeting/app/attendeeJoin/index!validateConferencePassword.action?site=box&confId="+confId+
                         "&trainingPassword=" + trainingPassword + "&joinTime=" + joinTime + "&registerUserName=" + URLEncoder.encode(registerUserName,"UTF-8");

            httpServletResponse.sendRedirect(URL);//重定向到会议系统
        }
    }
}
